/**
* @Description: WoShop商城
* @Author: 梧桐
* @Copyright: 武汉一一零七科技有限公司©版权所有
* @Link: www.s1107.com
* @Contact: QQ:2487937004
*/
<template>
	<view class="index_class">
		<view class="order-deta">
			<view class="order-info-time">
				<view>
					<view>{{orderInfo.order_zt}}</view>
					<view v-if="orderInfo.filter == 1">剩余{{orderInfo.sytime}}关闭</view>
					<view v-if="orderInfo.filter == 3">剩余{{orderInfo.sysh_time}}自动收货</view>
				</view>
				<image :src="imgSTATICURL+'images/img/addr-bao.png'" />
			</view>

			<view class="phone" v-if="orderInfo.filter == 3"
				@click="getnav('/pagesB/personalSon/logistics?psnum='+orderInfo.wulius.psnum+'&kdniao_code='+orderInfo.wulius.kdniao_code+'&logistics_name='+orderInfo.wulius.log_name)">
				<view style="width:20%;display:flex;justify-content:center">
					<i class="iconfont icon_e65e icon-bgc"></i>
				</view>
				<view class="tap_address">
					<view class="addrin">
						订单已发货{{orderInfo.wulius.log_name}}，快递单号{{orderInfo.wulius.psnum}}，联系电话{{orderInfo.wulius.telephone}}
					</view>
					<text style="color:#ccc">{{orderInfo.fh_time}}</text>
				</view>
				<i class="iconfont icon_e60c" style="width:7%;font-size:40upx;color:#ccc"></i>
			</view>

			<view class="phone">
				<view style="width:20%;display:flex;justify-content:center">
					<i class="iconfont icon_e712 icon-bgc"></i>
				</view>
				<view class="tap_address">
					<view>
						{{orderInfo.contacts}}
						<text style="padding-left:30upx">{{orderInfo.telephone}}</text>
					</view>
					<text>{{orderInfo.province + orderInfo.city + orderInfo.area + orderInfo.address}}</text>
				</view>
				<!-- <image class="p_bottom" src="/static/images/img/address_img.png" /> -->
			</view>

			<view class="fresh_list">
				<view class="order_bottom">
					<view class="bottom_top">
						<view>
							<i class="iconfont cart_e61d"></i>
							{{orderInfo.shop_name}}
						</view>
						<i class="iconfont order_all_right"></i>
					</view>
					<view class="bottom_img" v-for="(time2,index) in orderInfo.goodsinfo" :key="index">
						<image :src="time2.thumb_url"
							@click="getnav('/pagesC/homeSon/goodsDetails?id='+time2.goods_id)" />

						<view style="padding:0 40upx 0 20upx;flex:1">
							<view class="introduce" @click="getnav('/pagesC/homeSon/goodsDetails?id='+time2.goods_id)">
								{{time2.goods_name}}</view>
							<view class="arrt-str">{{time2.goods_attr_str}}</view>
						</view>
						<view style="font-size:24upx;text-align:right">
							¥{{time2.real_price}}
							<span>{{ time2.real_price | currency}}</span>
							<view style="text-align:right;color:#999">x{{time2.goods_num}}</view>

							<view class="shou_sure" v-if="orderInfo.filter == 2  || orderInfo.filter == 3">
								<view v-if="orderInfo.pinzhuangtai === 1">
									<span @click.stop="exchange(orderInfo.ordernumber)">退款</span>
								</view>
								<view v-if="orderInfo.pinzhuangtai !== 1">
									<view v-if="time2.th_status == 0 || time2.th_status == 8">
										<view v-if="orderInfo.fh_status == 1 ">
											<span
												@click.stop="getnav(`/pagesB/personalSon/Refundtype?order_num=${orderInfo.ordernumber}&orgoods_id=${time2.id}`)">退换</span>
										</view>
									</view>

									<view v-else-if="time2.th_status != 0">
										<span
											@click.stop="getnav(`/pagesB/personalSon/RefundDatecopy?order_num=${orderInfo.ordernumber}&orgoods_id=${time2.id}`)">
											<text v-if="time2.th_status == 1 || time2.th_status== 2">退款中</text>
											<text v-else-if="time2.th_status == 3">商家拒绝申请</text>
											<text v-else-if="time2.th_status == 4">退款完成</text>
											<text v-else-if="time2.th_status == 5 || time2.th_status == 6">换货中</text>
											<text v-else-if="time2.th_status == 7">商家拒绝申请</text>
										</span>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="or_number">
					<!-- <view class="number_text">
                        实付金额:<text>¥{{orderInfo.goods_price}}</text> <i class="iconfont order_all_right"></i>
          </view>-->

					<view class="number_sure" v-if="orderInfo.filter == 1">

						<u-button class="u-m-l-20" shape="circle" plain size="mini" @click="cancellation">取消订单
						</u-button>
						<u-button class="u-m-l-20" shape="circle" type="warning" plain size="mini"
							@click="getpay(orderInfo.ordernumber)">付款</u-button>
					</view>
					<!-- <view class="number_sure" v-if="orderInfo.filter == 3">

                        <span class="payment_order"  @click="getqrshouhuo">确认收货</span>
          </view>-->
				</view>
			</view>

			<view class="order_list order-list-info">
				<view>
					<text>支付方式</text>
					<text class="color">{{orderInfo.paytype}}</text>
				</view>
				<view>
					<text>商品价格</text>
					<text class="color">¥ {{orderInfo.goods_price}}</text>
					<span>{{ orderInfo.goods_price | currency}}</span>
				</view>
				<view>
					<text>物流公司</text>
					<text class="color">{{orderInfo.logistics}}</text>
				</view>
				<view>
					<text>物流单号</text>
					<text class="color">{{orderInfo.logistics_no}}</text>
				</view>
				<view>
					<text>运费</text>
					<text class="color">¥ {{orderInfo.freight}}</text>
					<span>{{ orderInfo.freight | currency}}</span>
				</view>

				<view>
					<text>优惠券</text>
					<text class="color">-¥ {{orderInfo.youhui_price}}</text>
					<span>-{{ orderInfo.youhui_price | currency}}</span>
				</view>
				<view class="order-name">
					<text>优惠信息</text>
					<text class="color">{{orderInfo.coupon_str}}</text>
				</view>
				<view class="order-name">
					<text>应付金额</text>
					<text class="color">¥ {{orderInfo.total_price}}</text>
					<span>{{ orderInfo.total_price | currency}}</span>
				</view>
			</view>

			<view class="order_list order-list-info" style="margin:20upx 0 60upx 0;">
				<view>
					<text>订单号:</text>
					<text class="color">{{orderInfo.ordernumber}}</text>
				</view>
				<view>
					<text>交易编号:</text>
					<text class="color">{{orderInfo.order_number}}</text>
				</view>
				<view>
					<text>创建时间</text>
					<text class="color">{{orderInfo.addtime}}</text>
				</view>
				<view v-if="orderInfo.filter == 2 || orderInfo.filter == 3 || orderInfo.filter == 4">
					<text>创建时间</text>
					<text class="color">{{orderInfo.pay_time}}</text>
				</view>
				<view v-if="orderInfo.filter == 3 || orderInfo.filter == 4">
					<text>发货时间</text>
					<text class="color">{{orderInfo.fh_time}}</text>
				</view>
				<view v-if="orderInfo.filter == 4">
					<text>收货时间</text>
					<text class="color">{{orderInfo.coll_time}}</text>
				</view>
			</view>


			<pay-pop ref="payPop" :totalPrice="orderInfo.total_price" @crosspay="crosspay">
				<div class="pay-btn" @click="$u.debounce(crosspay,1500)">确认支付</div>
			</pay-pop>
		</view>
	</view>
</template>

<script>
	let order_num = "",
		payOrderNumer; // 订单编号
	let page = 1; // 页码
	let providerList = []; // 支付通道

	let backindex = "";
	import payPop from "../../components/payPop";

	export default {
		components: {
			payPop
		},
		data() {
			return {
				imgSTATICURL: this.STATICURL,
				wechatMiniProgram: 0,
				orderInfo: {}, // 订单详情
				valShow: false,
				valueStatus: 0 // 更新页面状态 防止页面卡死
			}
		},
		onShow() {
			this.getMyorderinfo();
		},
		onLoad(option) {
			order_num = option.order_num;
			backindex = option.backindex;
			//#ifdef MP-WEIXIN
			this.wechatMiniProgram = 1;
			//#endif

			uni.setNavigationBarTitle({
				title: '订单详情'
			});
		},
		onBackPress() {
			console.log(backindex);
			if (backindex == 2) {
				uni.switchTab({
					url: "/pages/tabBar/Cart"
				});
				return true;
			}
		},

		watch: {
			valShow() {
				this.statusMath(this);
			}
		},
		methods: {
			exchange(ordernum) {
				console.log(ordernum);
				this.$Dialog
					.confirm({
						message: "确认退款吗？"
					})
					.then(() => {
						this.$loading();
						this.$http
							.exchange({
								order_num: ordernum
							})
							.then(res => {
								if (res.status === 200) {
									this.$toast(res.mess);
								}
							});
					});
			},
			getbacktel() {
				console.log(backindex);
				if (backindex == 2) {
					uni.switchTab({
						url: "/pages/tabBar/Cart"
					});
				} else {
					this.getback();
				}
			},

			getMyorderinfo() {
				this.$loading();
				this.$http.getMyorderinfo({
					order_num
				}).then(res => {
					if (res.status == 200) {
						this.orderInfo = res.data;
					}
				});
			},
			/**
			 * 取消订单
			 */
			cancellation() {
				this.$showModal({
					content: +'确认删除订单?'
				}).then(res => {
					if (res.confirm) {
						this.$loading();
						this.$http.getMyOrderquxiao({
							order_num
						}).then(res => {
							if (res.status == 200) {
								this.$toast(res.mess);
								this.getback();
							}
						});
					}
				});
			},
			/**
			 * 获取支付订单数据
			 */
			orderInfoStr(typeIndex = 2, pwd) {
				console.log(this.wechatMiniProgram,"this.wechatMiniProgram")
				let dataType = {
					order_nums: [order_num],
					zf_type: typeIndex
				};
				return new Promise(reslove => {
					this.$http.getzhifuorder(dataType).then(res => {
						if (res.status == 200) {
							this.$http
								.getzhifu({
									order_number: res.data.order_number,
									zf_type: res.data.zf_type,
									pay_password: pwd,
									wechat_miniprogram: this.wechatMiniProgram
								})
								.then(res => {
									console.log(JSON.stringify(res), "888888888888");
									reslove(res);
								});
						} else {
							this.$toast(res.mess);
						}
					});
				});
			},
			/**
			 * 支付
			 */
			async getpay(ordernumber) {

				payOrderNumer = ordernumber
				this.$refs.payPop.payModel = true;


			},
			async crosspay() {
				this.$refs.payPop.payModel = false;
				this.$loading()
				const ref = this.$refs.payPop
				const orderInfo = await this.orderInfoStr(ref.payType);
				if (ref.payType === 5) {
					ref.orderNumber = orderInfo.order_number
					ref.bankModel = true
					return
				}
				ref.payinfos = await orderInfo.data.infos
				ref.crosspay()
				this.$hideLoading()
			},
			/**
			 *
			 */
			hidePopup() {
				this.$refs.popupRef.show();
			},
			/**
			 * 余额支付
			 */
			async codeShow(index) {
				// 接受子组件传的值  点击的六位密码值
				/**
				 * 确认支付
				 */
				this.$loading();
				let paydata = await this.orderInfoStr(3, index.cord);

				if (paydata.status == 200) {
					this.$toast(paydata.mess);
					setTimeout(() => {
						this.getback();
					}, 1000);
				} else {
					this.$toast(paydata.mess);
				}

				console.log(paydata);
			},
			hideAl(bal) {
				this.valShow = false;
			}
		}
	};
</script>

<style lang="scss" scoped>
	.shou_sure {
		span {
			display: block;
			// width: 100upx;
			height: 40upx;
			padding: 0 20upx;
			line-height: 40upx;
			border-radius: 20upx;
			border: 1upx solid #999;
			color: #999;
			text-align: center;
			font-size: 24upx;
		}
	}

	.order-list-info {
		>view {
			margin: 10upx 0;

			text:nth-child(2) {
				display: block;
				flex: 1;
				text-align: left;
			}

			text:nth-child(1) {
				display: block;
				width: 30%;
				text-align: left;
			}
		}
	}
</style>
